import { postHttp, postHttpParam, putHttp } from "..";
import { encryptedData, publicKey } from "../../utils/encryptedData";

// 申请入住类型
export interface CheckInState {
  // 注册邮箱
  email: string;
  // 验证码
  code: string;
  // 用户的密码
  pwd1: string;
  // 重复输入用户的密码（这个地方客户端也要校验是否相同）
  pwd2: string;
  // 姓名
  name: string;
  // 就职医院
  inauguralHospital: string;
  // 科室id(调用查询科室列表接口获取)
  departmentId: string;
  // 职称id（调用查询职称列表接口获取）
  jobTitleId: string;
  // 个人简介
  personalProfile: string;
  // 擅长领域
  goodField: string;
}

// 申请入住
export const CheckIn = async (data: CheckInState) => {
  data.pwd1 = encryptedData(publicKey, data.pwd1) as string
  data.pwd2 = data.pwd1
  const resp = await postHttp("/health/doctor/v1/applyJoin", data, {
    "Content-Type": "application/json;charset=UTF-8",
  });
  return resp;
};

// 获取验证码
export const getEmailCode = async (email: string) => {
  const resp = await postHttpParam("/health/doctor/v1/sendEmailCode", { email });
  return resp;
};

// 校验验证码
export const checkEmailCode = async (data: { email: string; code: string }) => {
  const resp = await postHttp("/health/doctor/v1/checkCode", data);
  return resp;
};

// 重置密码
export const repeatPassword = async (data: {
  email: string;
  pwd1: string;
  pwd2: string;
}) => {
  const resp = await putHttp("/health/doctor/v1/resetUserPwd", data);
  return resp;
};
